var e = require("../../../../../../common/vendor.js"), r = require("../z-paging-utils.js"), t = require("../z-paging-constant.js"), s = require("../z-paging-enum.js"), h = {
    props: {
        refresherThemeStyle: {
            type: String,
            default: r.u.gc("refresherThemeStyle", "")
        },
        refresherImgStyle: {
            type: Object,
            default: function() {
                return r.u.gc("refresherImgStyle", {});
            }
        },
        refresherTitleStyle: {
            type: Object,
            default: function() {
                return r.u.gc("refresherTitleStyle", {});
            }
        },
        refresherUpdateTimeStyle: {
            type: Object,
            default: function() {
                return r.u.gc("refresherUpdateTimeStyle", {});
            }
        },
        watchRefresherTouchmove: {
            type: Boolean,
            default: r.u.gc("watchRefresherTouchmove", !1)
        },
        loadingMoreThemeStyle: {
            type: String,
            default: r.u.gc("loadingMoreThemeStyle", "")
        },
        refresherOnly: {
            type: Boolean,
            default: r.u.gc("refresherOnly", !1)
        },
        refresherDefaultDuration: {
            type: [ Number, String ],
            default: r.u.gc("refresherDefaultDuration", 100)
        },
        refresherCompleteDelay: {
            type: [ Number, String ],
            default: r.u.gc("refresherCompleteDelay", 0)
        },
        refresherCompleteDuration: {
            type: [ Number, String ],
            default: r.u.gc("refresherCompleteDuration", 300)
        },
        refresherCompleteScrollable: {
            type: Boolean,
            default: r.u.gc("refresherCompleteScrollable", !1)
        },
        useCustomRefresher: {
            type: Boolean,
            default: r.u.gc("useCustomRefresher", !0)
        },
        refresherFps: {
            type: [ Number, String ],
            default: r.u.gc("refresherFps", 40)
        },
        refresherMaxAngle: {
            type: [ Number, String ],
            default: r.u.gc("refresherMaxAngle", 40)
        },
        refresherAngleEnableChangeContinued: {
            type: Boolean,
            default: r.u.gc("refresherAngleEnableChangeContinued", !1)
        },
        refresherDefaultText: {
            type: [ String, Object ],
            default: r.u.gc("refresherDefaultText", null)
        },
        refresherPullingText: {
            type: [ String, Object ],
            default: r.u.gc("refresherPullingText", null)
        },
        refresherRefreshingText: {
            type: [ String, Object ],
            default: r.u.gc("refresherRefreshingText", null)
        },
        refresherCompleteText: {
            type: [ String, Object ],
            default: r.u.gc("refresherCompleteText", null)
        },
        refresherDefaultImg: {
            type: String,
            default: r.u.gc("refresherDefaultImg", null)
        },
        refresherPullingImg: {
            type: String,
            default: r.u.gc("refresherPullingImg", null)
        },
        refresherRefreshingImg: {
            type: String,
            default: r.u.gc("refresherRefreshingImg", null)
        },
        refresherCompleteImg: {
            type: String,
            default: r.u.gc("refresherCompleteImg", null)
        },
        refresherRefreshingAnimated: {
            type: Boolean,
            default: r.u.gc("refresherRefreshingAnimated", !0)
        },
        refresherEndBounceEnabled: {
            type: Boolean,
            default: r.u.gc("refresherEndBounceEnabled", !0)
        },
        refresherEnabled: {
            type: Boolean,
            default: r.u.gc("refresherEnabled", !0)
        },
        refresherThreshold: {
            type: [ Number, String ],
            default: r.u.gc("refresherThreshold", "80rpx")
        },
        refresherDefaultStyle: {
            type: String,
            default: r.u.gc("refresherDefaultStyle", "black")
        },
        refresherBackground: {
            type: String,
            default: r.u.gc("refresherBackground", "transparent")
        },
        refresherFixedBackground: {
            type: String,
            default: r.u.gc("refresherFixedBackground", "transparent")
        },
        refresherFixedBacHeight: {
            type: [ Number, String ],
            default: r.u.gc("refresherFixedBacHeight", 0)
        },
        refresherOutRate: {
            type: Number,
            default: r.u.gc("refresherOutRate", .65)
        },
        refresherPullRate: {
            type: Number,
            default: r.u.gc("refresherPullRate", .75)
        },
        showRefresherUpdateTime: {
            type: Boolean,
            default: r.u.gc("showRefresherUpdateTime", !1)
        },
        refresherUpdateTimeKey: {
            type: String,
            default: r.u.gc("refresherUpdateTimeKey", "default")
        },
        refresherVibrate: {
            type: Boolean,
            default: r.u.gc("refresherVibrate", !1)
        },
        refresherNoTransform: {
            type: Boolean,
            default: r.u.gc("refresherNoTransform", !1)
        },
        useRefresherStatusBarPlaceholder: {
            type: Boolean,
            default: r.u.gc("useRefresherStatusBarPlaceholder", !1)
        }
    },
    data: function() {
        return {
            R: s.Enum.Refresher,
            refresherStatus: s.Enum.Refresher.Default,
            refresherTouchstartY: 0,
            lastRefresherTouchmove: null,
            refresherReachMaxAngle: !0,
            refresherTransform: "translateY(0px)",
            refresherTransition: "",
            finalRefresherDefaultStyle: "black",
            refresherRevealStackCount: 0,
            refresherCompleteTimeout: null,
            refresherCompleteSubTimeout: null,
            refresherEndTimeout: null,
            isTouchmovingTimeout: null,
            refresherTriggered: !1,
            isTouchmoving: !1,
            isTouchEnded: !1,
            isUserPullDown: !1,
            privateRefresherEnabled: -1,
            privateShowRefresherWhenReload: !1,
            customRefresherHeight: -1,
            showCustomRefresher: !1,
            doRefreshAnimateAfter: !1,
            isRefresherInComplete: !1,
            pullDownTimeStamp: 0,
            moveDis: 0,
            oldMoveDis: 0,
            currentDis: 0,
            oldCurrentMoveDis: 0,
            oldRefresherTouchmoveY: 0,
            oldTouchDirection: "",
            oldEmitedTouchDirection: "",
            oldPullingDistance: -1,
            refresherThresholdUpdateTag: 0
        };
    },
    watch: {
        refresherDefaultStyle: {
            handler: function(e) {
                e.length && (this.finalRefresherDefaultStyle = e);
            },
            immediate: !0
        },
        refresherStatus: function(e) {
            e === s.Enum.Refresher.Loading && this._cleanRefresherEndTimeout(), this.refresherVibrate && e === s.Enum.Refresher.ReleaseToRefresh && this._doVibrateShort(), 
            this.$emit("refresherStatusChange", e), this.$emit("update:refresherStatus", e);
        },
        refresherEnabled: function(e) {
            !e && this.endRefresh();
        }
    },
    computed: {
        pullDownDisTimeStamp: function() {
            return 1e3 / this.refresherFps;
        },
        finalRefresherEnabled: function() {
            return !this.useChatRecordMode && (-1 === this.privateRefresherEnabled ? this.refresherEnabled : 1 === this.privateRefresherEnabled);
        },
        finalRefresherThreshold: function() {
            var e = this.refresherThreshold, t = !1;
            return "80rpx" === e && (t = !0, this.showRefresherUpdateTime && (e = "120rpx")), 
            t && this.customRefresherHeight > 0 ? this.customRefresherHeight + this.finalRefresherThresholdPlaceholder : r.u.convertToPx(e) + this.finalRefresherThresholdPlaceholder;
        },
        finalRefresherThresholdPlaceholder: function() {
            return this.useRefresherStatusBarPlaceholder ? this.statusBarHeight : 0;
        },
        finalRefresherFixedBacHeight: function() {
            return r.u.convertToPx(this.refresherFixedBacHeight);
        },
        finalRefresherThemeStyle: function() {
            return this.refresherThemeStyle.length ? this.refresherThemeStyle : this.defaultThemeStyle;
        },
        finalRefresherOutRate: function() {
            var e = this.refresherOutRate;
            return e = Math.max(0, e), e = Math.min(1, e);
        },
        finalRefresherPullRate: function() {
            var e = this.refresherPullRate;
            return e = Math.max(0, e);
        },
        finalRefresherTransform: function() {
            return this.refresherNoTransform || "translateY(0px)" === this.refresherTransform ? "none" : this.refresherTransform;
        },
        finalShowRefresherWhenReload: function() {
            return this.showRefresherWhenReload || this.privateShowRefresherWhenReload;
        },
        finalRefresherTriggered: function() {
            return !(!this.finalRefresherEnabled || this.useCustomRefresher) && this.refresherTriggered;
        },
        showRefresher: function() {
            var e = this.finalRefresherEnabled && this.useCustomRefresher;
            return -1 === this.customRefresherHeight && e && this.updateCustomRefresherHeight(), 
            e;
        },
        hasTouchmove: function() {
            return this.watchRefresherTouchmove;
        }
    },
    methods: {
        endRefresh: function() {
            var e = this;
            this.totalData = this.realTotalData, this._refresherEnd(), this._endSystemLoadingAndRefresh(), 
            this._handleScrollViewBounce({
                bounce: !0
            }), this.$nextTick(function() {
                e.refresherTriggered = !1;
            });
        },
        handleRefresherStatusChanged: function(e) {
            this.refresherStatusChangedFunc = e;
        },
        updateCustomRefresherHeight: function() {
            var e = this;
            r.u.delay(function() {
                return e.$nextTick(e._updateCustomRefresherHeight);
            });
        },
        _onRefresh: function() {
            var e = arguments.length > 0 && void 0 !== arguments[0] && arguments[0], r = !(arguments.length > 1 && void 0 !== arguments[1]) || arguments[1];
            (!e || this.finalRefresherEnabled && !this.useCustomRefresher) && (this.$emit("onRefresh"), 
            this.$emit("Refresh"), this.loading || this.isRefresherInComplete || (this.loadingType = s.Enum.LoadingType.Refresher, 
            this.nShowRefresherReveal || (this.isUserPullDown = r, this.isUserReload = !r, this._startLoading(!0), 
            this.refresherTriggered = !0, this.reloadWhenRefresh && r && (this.useChatRecordMode ? this._onLoadingMore("click") : this._reload(!1, !1, r)))));
        },
        _onRestore: function() {
            this.refresherTriggered = "restore", this.$emit("onRestore"), this.$emit("Restore");
        },
        _handleRefresherTouchstart: function(e) {
            !this.loading && this.isTouchEnded && (this.isTouchmoving = !1), this.loadingType = s.Enum.LoadingType.Refresher, 
            this.isTouchmovingTimeout && clearTimeout(this.isTouchmovingTimeout), this.isTouchEnded = !1, 
            this.refresherTransition = "", this.refresherTouchstartY = e.touchY, this.$emit("refresherTouchstart", this.refresherTouchstartY), 
            this.lastRefresherTouchmove = e, this._cleanRefresherCompleteTimeout(), this._cleanRefresherEndTimeout();
        },
        _handleRefresherTouchmove: function(e, r) {
            this.refresherReachMaxAngle = !0, this.isTouchmovingTimeout && clearTimeout(this.isTouchmovingTimeout), 
            this.isTouchmoving = !0, this.isTouchEnded = !1, this.refresherStatus = e >= this.finalRefresherThreshold ? s.Enum.Refresher.ReleaseToRefresh : this.refresherStatus = s.Enum.Refresher.Default, 
            this.moveDis = e;
        },
        _handleRefresherTouchend: function(e) {
            var t = this;
            this.isTouchmovingTimeout && clearTimeout(this.isTouchmovingTimeout), this.refresherReachMaxAngle = !0, 
            this.isTouchEnded = !0;
            var h = this.finalRefresherThreshold;
            e >= h && this.refresherStatus === s.Enum.Refresher.ReleaseToRefresh ? (r.u.delay(function() {
                t._emitTouchmove({
                    pullingDistance: h,
                    dy: t.moveDis - h
                });
            }, .1), this.moveDis = h, this.refresherStatus = s.Enum.Refresher.Loading, this._doRefresherLoad()) : (this._refresherEnd(), 
            this.isTouchmovingTimeout = r.u.delay(function() {
                t.isTouchmoving = !1;
            }, this.refresherDefaultDuration)), this.scrollEnable = !0, this.$emit("refresherTouchend", e);
        },
        _handleListTouchstart: function() {
            this.useChatRecordMode && this.autoHideKeyboardWhenChat && (e.index.hideKeyboard(), 
            this.$emit("hidedKeyboard"));
        },
        _handleScrollViewBounce: function(e) {
            var r = e.bounce;
            this.usePageScroll || this.scrollToTopBounceEnabled || (this.wxsScrollTop <= 5 ? (this.refresherTransition = "", 
            this.scrollEnable = r) : r && (this.scrollEnable = r));
        },
        _handleWxsPullingDownStatusChange: function(e) {
            this.wxsOnPullingDown = e, e && !this.useChatRecordMode && (this.renderPropScrollTop = 0);
        },
        _handleWxsPullingDown: function(e) {
            var r = e.moveDis, t = e.diffDis;
            this._emitTouchmove({
                pullingDistance: r,
                dy: t
            });
        },
        _handleTouchDirectionChange: function(e) {
            var r = e.direction;
            this.$emit("touchDirectionChange", r);
        },
        _handlePropUpdate: function() {
            this.wxsPropType = r.u.getTime().toString();
        },
        _refresherEnd: function() {
            var e = this, h = !(arguments.length > 0 && void 0 !== arguments[0]) || arguments[0], i = arguments.length > 1 && void 0 !== arguments[1] && arguments[1], n = arguments.length > 2 && void 0 !== arguments[2] && arguments[2], o = !(arguments.length > 3 && void 0 !== arguments[3]) || arguments[3];
            if (this.loadingType === s.Enum.LoadingType.Refresher) {
                var u = i && (n || this.showRefresherWhenReload) ? this.refresherCompleteDelay : 0, f = u > 0 ? s.Enum.Refresher.Complete : s.Enum.Refresher.Default;
                if (this.finalShowRefresherWhenReload) {
                    var a = this.refresherRevealStackCount;
                    if (this.refresherRevealStackCount--, a > 1) return;
                }
                this._cleanRefresherEndTimeout(), this.refresherEndTimeout = r.u.delay(function() {
                    e.refresherStatus = f;
                }, this.refresherStatus !== s.Enum.Refresher.Default && f === s.Enum.Refresher.Default ? this.refresherCompleteDuration : 0), 
                u > 0 && (this.isRefresherInComplete = !0), this._cleanRefresherCompleteTimeout(), 
                this.refresherCompleteTimeout = r.u.delay(function() {
                    var t = 1, h = e.refresherEndBounceEnabled && i ? "cubic-bezier(0.19,1.64,0.42,0.72)" : "linear";
                    i && (t = e.refresherEndBounceEnabled ? e.refresherCompleteDuration / 1e3 : e.refresherCompleteDuration / 3e3), 
                    e.refresherTransition = "transform ".concat(i ? t : e.refresherDefaultDuration / 1e3, "s ").concat(h), 
                    e.wxsPropType = e.refresherTransition + "end" + r.u.getTime(), e.moveDis = 0, f === s.Enum.Refresher.Complete && (e.refresherCompleteSubTimeout && (clearTimeout(e.refresherCompleteSubTimeout), 
                    e.refresherCompleteSubTimeout = null), e.refresherCompleteSubTimeout = r.u.delay(function() {
                        e.$nextTick(function() {
                            e.refresherStatus = s.Enum.Refresher.Default, e.isRefresherInComplete = !1;
                        });
                    }, 800 * t)), e._emitTouchmove({
                        pullingDistance: 0,
                        dy: e.moveDis
                    });
                }, u);
            }
            o && (r.u.delay(function() {
                return e.loading = !1;
            }, h ? t.c.delayTime : 0), n && this._onRestore());
        },
        _doRefresherRefreshAnimate: function() {
            this._cleanRefresherCompleteTimeout(), !this.doRefreshAnimateAfter && this.finalShowRefresherWhenReload && -1 === this.customRefresherHeight && "80rpx" === this.refresherThreshold ? this.doRefreshAnimateAfter = !0 : (this.refresherRevealStackCount++, 
            this.wxsPropType = "begin" + r.u.getTime(), this.moveDis = this.finalRefresherThreshold, 
            this.refresherStatus = s.Enum.Refresher.Loading, this.isTouchmoving = !0, this.isTouchmovingTimeout && clearTimeout(this.isTouchmovingTimeout), 
            this._doRefresherLoad(!1));
        },
        _doRefresherLoad: function() {
            var e = !(arguments.length > 0 && void 0 !== arguments[0]) || arguments[0];
            this._onRefresh(!1, e), this.loading = !0;
        },
        _updateCustomRefresherHeight: function() {
            var e = this;
            this._getNodeClientRect(".zp-custom-refresher-slot-view").then(function(r) {
                e.customRefresherHeight = r ? r[0].height : 0, e.showCustomRefresher = e.customRefresherHeight > 0, 
                e.doRefreshAnimateAfter && (e.doRefreshAnimateAfter = !1, e._doRefresherRefreshAnimate());
            });
        },
        _emitTouchmove: function(e) {
            e.viewHeight = this.finalRefresherThreshold, e.rate = e.viewHeight > 0 ? e.pullingDistance / e.viewHeight : 0, 
            this.hasTouchmove && this.oldPullingDistance !== e.pullingDistance && this.$emit("refresherTouchmove", e), 
            this.oldPullingDistance = e.pullingDistance;
        },
        _cleanRefresherCompleteTimeout: function() {
            this.refresherCompleteTimeout = this._cleanTimeout(this.refresherCompleteTimeout);
        },
        _cleanRefresherEndTimeout: function() {
            this.refresherEndTimeout = this._cleanTimeout(this.refresherEndTimeout);
        }
    }
};

exports.refresherModule = h;